/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import simplemetrosystem.control.EditCommandManager;
import simplemetrosystem.view.MetroFrame;

/**
 *
 * @author Eric Qian
 */
public class UndoActionListener implements ActionListener {

    public UndoActionListener(MetroFrame frame) {
        this.frame = frame;
    }

    public void actionPerformed(ActionEvent e) {
        undo();
    }

    // control + z toggles the undo event.
    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
            isControlDown = true;
        } else if (isControlDown && e.getKeyCode() == KeyEvent.VK_Z) {
            this.undo();
        }
    }
    
    public void undo(){
        EditCommandManager.getInstance().undo();
    }
    
    private MetroFrame frame;
    private boolean isControlDown;
}
